<template>
  <a-modal
    title="选择产品"
    width="60%"
    :visible="visible"
    :confirmLoading="loading"
    @ok="handleSubmit"
    @cancel="
      () => {
        this.visible = false
      }
    "
  >
    <div>
      <!-- <a-select style="width: 120px" placeholder="请选择" allowClear v-model="queryParam.condition">
        <a-select-option style="width: 120px" key="cInvName">产品名称</a-select-option>
      </a-select> -->
      <a-input style="width: 120px" v-model="queryParam.keyword" placeholder="产品名称"></a-input>
      <a-button style="margin-bottom:12px;margin-left: 8px" type="primary" @click="getDataList()">查询</a-button>
      <a-button style="margin-left: 8px" @click=";(queryParam = { condition: 'cInvName' }), getDataList()"
        >重置
      </a-button>
    </div>
    <a-table
      ref="table"
      :scroll="{ y: scroll }"
      :columns="columns"
      :rowKey="(row, index) => row.Id"
      :dataSource="data"
      :pagination="pagination"
      :loading="loading"
      @change="handleTableChange"
      :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange, type: 'radio' }"
      :bordered="true"
      size="small"
    >
      <template slot="dataIndex" slot-scope="text, record, index">
        <span>{{ (pagination.current - 1) * pagination.pageSize + index + 1 }}</span>
      </template>
    </a-table>
  </a-modal>
</template>

<script>
const columns = [
  // { title: '备注', dataIndex: 'Remark', width: '10%' },
  { title: '产品编码', dataIndex: 'cInvCode' },
  { title: '产品名称', dataIndex: 'cInvName' },

  { title: '规格型号 ', dataIndex: 'cInvStd' }
  // { title: '零售单价 ', dataIndex: 'iInvSaleCost' },
  // { title: '采购员', dataIndex: 'cPurPersonCode' },
  // { title: '更新时间', dataIndex: 'UpdateTime' },
  // {

  // { title: '操作', dataIndex: 'action', align: 'left', scopedSlots: { customRender: 'action' } }
]
export default {
  data() {
    return {
      data: [],
      visible: false,
      loading: false,
      selectedRowKeys: [],
      selectedRows: [],
      pagination: {
        current: 1,
        pageSize: 25,
        pageSizeOptions: ['25', '50', '100'],
        showSizeChanger: true,
        onShowSizeChange: (current, pageSize) => (this.pageSize = pageSize),
        showTotal: (total, range) => `总数:${total} 当前:${range[0]}-${range[1]}`
      },
      filters: {},
      sorter: { field: 'Id', order: 'desc' },
      queryParam: { condition: 'cInvName' },
      columns
    }
  },
  computed: {
    scroll() {
      return Number(document.documentElement.clientHeight) * 0.45
    }
  },
  methods: {
    openForm() {
      this.selectedRowKeys = []
      this.selectedRows = []
      this.queryParam = { condition: 'cInvName' }
      this.pagination.current = 1
      this.visible = true
      this.getDataList()
    },
    handleSubmit() {
      this.$emit('handlerClose', this.selectedRows)
      this.visible = false
    },
    onSelectChange(selectedRowKeys, selectedRows) {
      //console.log(selectedRowKeys, selectedRows)
      this.selectedRowKeys = selectedRowKeys
      this.selectedRows = selectedRows
      //console.log(this.selectedRows)
    },
    handleTableChange(pagination, filters, sorter) {
      this.pagination = { ...pagination }
      this.filters = { ...filters }

      this.getDataList()
    },
    getDataList() {
      this.loading = true

      this.$http
        .post('/ProductManagement/Inventory/GetDataList', {
          PageIndex: this.pagination.current,
          PageRows: this.pagination.pageSize,
          SortField: this.sorter.field || 'Id',
          SortType: this.sorter.order,
          Search: this.queryParam
        })
        .then(resJson => {
          this.loading = false
          this.data = resJson.Data
          const pagination = { ...this.pagination }
          pagination.total = resJson.Total
          this.pagination = pagination
        })
    }
  }
}
</script>

<style></style>
